/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sgsmcan.Dao;

import com.sgsmcan.Entidad.Enfermedad;
import com.sgsmcan.Entidad.EventoSerenoPerro;
import com.sgsmcan.Entidad.SerenoPerro;
import com.sgsmcan.Hibernate.HibernateUtil;
import com.sgsmcan.Utils.Utilitario;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author David
 */
public class EventoSerenoPerroImpl extends HibernateDao<EventoSerenoPerro> implements EventoSerenoPerroDao<EventoSerenoPerro>{
    
    private final String  CLASE_EVENTO = "[EventoSerenoPerroImpl]";

    @Override
    public List<EventoSerenoPerro> getEventoSerenoPerro() {
        List<EventoSerenoPerro> list = null;
        Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            list = session.createCriteria(EventoSerenoPerro.class).list();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (session != null) {
                session.close();
            }
        }
        return list;
    }

    @Override
    public List<EventoSerenoPerro> getEventoSerenoPerroByEvento(int idEvento) {
        Session session = null;
        List<EventoSerenoPerro> auxiliar = null;
        try{
            session = HibernateUtil.getSessionFactory().openSession();
            Query query = session.createQuery("FROM EventoSerenoPerro WHERE evento.idEvento =:idEvento");
            query.setParameter("idEvento", idEvento);
            auxiliar = query.list();
        }catch(HibernateException e){
           Utilitario.LOG.error(CLASE_EVENTO+ " Error al obtener getEventoSerenoPerroByEvento", e);
           e.printStackTrace();
        }finally{
            if(session!= null){
                session.close();
            }
        }
        return auxiliar;
    }

    @Override
    public EventoSerenoPerro getESP(int idEvento, SerenoPerro sp) {
        Session session = null;
        EventoSerenoPerro auxiliar = null;
        try{
            session = HibernateUtil.getSessionFactory().openSession();
            Query query = session.createQuery("FROM EventoSerenoPerro WHERE evento.idEvento =:idEvento AND serenoPerro = :sp");
            query.setParameter("idEvento", idEvento);
            query.setParameter("sp", sp);
            auxiliar = (EventoSerenoPerro) query.uniqueResult();
        }catch(HibernateException e){
           Utilitario.LOG.error(CLASE_EVENTO+ " Error al obtener getEventoSerenoPerroByEvento", e);
           e.printStackTrace();
        }finally{
            if(session!= null){
                session.close();
            }
        }
        return auxiliar;
    }
    
}
